#!/bin/sh

# Slackware build script for slackins
# Written by ppr:kut <hmwiesinger@gmx.at>
# Modified by Robby Workman <rworkman@slackbuilds.org>

PRGNAM=slackins
VERSION=3.0
ARCH=${ARCH:-i486}
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}
CWD=$(pwd)
TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

# This should be safe enough, as it's still only executable by members
# of the wheel group, AND it still asks for the root password before
# continuing.
SETSUID=${SETSUID:-yes}

if [ "$ARCH" = "i486" ]; then
  SLKCFLAGS="-O2 -march=i486 -mtune=i686"
elif [ "$ARCH" = "i686" ]; then
  SLKCFLAGS="-O2 -march=i686 -mtune=i686"
fi

set -e

rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP
rm -rf $PRGNAM-$VERSION
tar xvzf $CWD/$PRGNAM-$VERSION.tar.gz
cd $PRGNAM-$VERSION
chown -R root:root .
chmod -R u+w,go+r-w,a-s .

CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
./configure \
    --prefix=/usr \
    --sysconfdir=/etc \
    --localstatedir=/var

make

# We won't be using the Makefile's 'install' target - it's ugly.  (--rworkman)

# Are we going to do this suid?
if [ "$SETSUID" = "yes" ]; then
  install -D -m 4750 -g wheel bin/slackins $PKG/usr/bin/slackins
else
  install -D -m 0750 -g wheel bin/slackins $PKG/usr/bin/slackins
fi

install -D -m 0755 src/script/removedlog $PKG/usr/bin/removedlog

# Add the icons and menu entry
install -D -m 0644 icon/s3.png $PKG/usr/share/pixmaps/s3.png
install -D -m 0644 icon/SlackIns.desktop $PKG/usr/share/applnk/Utilities/SlackIns.desktop

# Let's not clobber config files
install -D -m 0644 modules/slack-serv/conf/slackproc.conf $PKG/etc/slackins/slackproc.conf.new
install -D -m 0644 modules/slack-serv/conf/slack_descrc $PKG/etc/slackins/slack_descrc.new

mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
cp -a AUTHORS ChangeLog COPYING INSTALL $PKG/usr/doc/$PRGNAM-$VERSION
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cat $CWD/doinst.sh > $PKG/install/doinst.sh

cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.tgz
